﻿{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="{:url('goods/goodsCategoryList')}" class="n_tab_list">分类列表</a>
            <a href="{:url('goods/goods_add_cate')}" class="n_tab_add"><i class="Hui-iconfont">&#xe604;</i>添加分类</a>
            <div class="cl"></div>
        </div>
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr class="text-c">
                <th><i class="Hui-iconfont">&#xe6f5;</i></th>
                <th>排序</th>
                <th>分类名称</th>
                <th>分类简称</th>
                <th>分类图片</th>
                <th>是否显示</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach name="category_list" item="v1"}
            <tr class="pid_0" style="height: 30px;">
                <td>
                    {if condition="$v1['child_list'] neq array()"}
                    <a href="javascript:;" onclick="tab_switch({$v1['cate_id']})" class="tab_jia_{$v1['cate_id']}" style="display: block;"><i class="Hui-iconfont">&#xe600;</i></a>
                    <a href="javascript:;" onclick="tab_switch({$v1['cate_id']})" class="tab_jian_{$v1['cate_id']}" style="display: none;"><i class="Hui-iconfont">&#xe6a1;</i></a>
                    {/if}
                </td>
                <td style="text-align: center;"><input type="text" class="sort input-common" fieldid="{$v1['cate_id']}" fieldname="sort" value="{$v1['sort']}" size="1" style="margin-left:3px;"></td>
                <td style="text-align: center;"><input class="input-common" type="text" fieldid="{$v1['cate_id']}" fieldname="cate_name" value="{$v1['cate_name']}" style="width: 150px;"></td>
                <td style="text-align: center;"><input class="input-common" type="text" fieldid="{$v1['cate_id']}" fieldname="short_name" value="{$v1['short_name']}" style="width: 150px;"></td>
                <td style="text-align: center;"><img src="{$v1['cate_pic']}" onerror="this.src='/public/goods/img/default_goods_image_240.gif'" width="50px;"></td>
                <td style="text-align: center;">
                    {if $v1['is_visible']==1}
                    <span class="label label-success radius">是</span>
                    {else}
                    <span class="label label-default radius">否</span>
                    {/if}
                </td>
                <td style="text-align: center;">
                    <a style="text-decoration:none;color:#0066cc;" title="编辑" onclick="goods_cate_edit('类型编辑','__CONF_SITE__admin/goods/updateGoodsCate&cate_id={$v1.cate_id}','1000','800')" href="javascript:;">
                    编辑
                    </a>
                    <a style="text-decoration:none;color:#0066cc;" title="删除" href="javascript:void(0);" onclick="delCategory({$v1['cate_id']})">
                  删除
                    </a>
                </td>
            </tr>
            {foreach name="v1['child_list']" item="v2"}
            <tr class="pid_{$v1['cate_id']}" style="height: 30px;display: none;">
                <td>
                    {if condition="$v2['child_list'] neq array()"}
                    <a href="javascript:;" onclick="tab_switch({$v2['cate_id']})" class="tab_jian_{$v2['cate_id']}" style="display: block;"><i class="Hui-iconfont">&#xe6a1;</i></a>
                    <a href="javascript:;" onclick="tab_switch({$v2['cate_id']})" class="tab_jia_{$v2['cate_id']}" style="display: none;"><i class="Hui-iconfont">&#xe600;</i></a>
                    {/if}
                </td>
                <td style="text-align: center;"><input type="text" class="sort input-common" fieldid="{$v2['cate_id']}" fieldname="sort"  value="{$v2['sort']}" size="1"></td>
                <td style="text-align: center;"><span style="color:#ccc;">|——</span> <input type="text" class="input-common" fieldid="{$v2['cate_id']}" fieldname="cate_name" value="{$v2['cate_name']}" style="width: 100px;"></td>
                <td style="text-align: center;"><input type="text" class="input-common" fieldid="{$v2['cate_id']}" fieldname="short_name" value="{$v2['short_name']}" style="width: 150px;"></td>
                <td style="text-align: center;"><img src="{$v2['cate_pic']}" width="50px;"></td>
                <td style="text-align: center;">
                    {if $v2['is_visible']==1}
                    <span class="label label-success radius">是</span>
                    {else}
                    <span class="label label-default radius">否</span>
                    {/if}
                </td>
                <td style="text-align: center;">
                    <a style="text-decoration:none;color:#0066cc;" title="编辑" onclick="goods_cate_edit('类型编辑','__CONF_SITE__admin/goods/updateGoodsCate&cate_id={$v2.cate_id}','800','500')" href="javascript:;">
                        编辑
                    </a>
                    <a style="text-decoration:none;color:#0066cc;" title="删除" href="javascript:void(0);" onclick="delCategory({$v2['cate_id']})">
                      删除
                    </a>
                </td>
            </tr>
            {foreach name="v2['child_list']" item="v3"}
            <tr class="pid_{$v2['cate_id']} pid_{$v1['cate_id']}" style="height: 30px;display:none;">
                <td></td>
                <td style="text-align: center;"><input type="text" class="sort input-common" fieldid="{$v3['cate_id']}" fieldname="sort"  value="{$v3['sort']}" size="1"></td>
                <td style="text-align: center;"><span style="color:#ccc;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|——</span> <input class="input-common" type="text" fieldid="{$v3['cate_id']}" fieldname="cate_name" value="{$v3['cate_name']}" style="width: 100px;"></td>
                <td style="text-align: center;"><input type="text" class="input-common" fieldid="{$v3['cate_id']}" fieldname="short_name" value="{$v3['short_name']}" style="width: 150px;"></td>
                <td style="text-align: center;"><img src="{$v3['cate_pic']}" width="50px;"></td>
                <td style="text-align: center;">
                    {if $v3['is_visible']==1}
                    <span class="label label-success radius">是</span>
                    {else}
                    <span class="label label-default radius">否</span>
                    {/if}
                </td>
                <td style="text-align: center;">
                    <a style="text-decoration:none;color:#0066cc;" title="编辑" onclick="goods_cate_edit('类型编辑','__CONF_SITE__admin/goods/updateGoodsCate&cate_id={$v3.cate_id}','800','500')" href="javascript:;">
                        编辑
                    </a>
                    <a style="text-decoration:none;color:#0066cc;" title="删除" href="javascript:void(0);" onclick="delCategory({$v3['cate_id']})">
                        删除
                    </a>
                </td>
            </tr>
            {/foreach}
            {/foreach}
            {/foreach}
            </tbody>
        </table>
    </article>
    <div class="n_page_no">
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    /*
     参数解释：
     title	标题
     url		请求的url
     id		需要操作的数据id
     w		弹出层宽度（缺省调默认值）
     h		弹出层高度（缺省调默认值）
     */
    /*分类-编辑*/
    function goods_cate_edit(title,url,w,h){
        layer_show(title,url,w,h);
    }
    $(".table input").change(function(){
        var fieldid = $(this).attr('fieldid');
        var fieldname = $(this).attr('fieldname');
        var fieldvalue = $(this).val();
        if(fieldvalue == ''){
            layer.msg('不能为空！', {icon: 2, time: 1000});
        }else{
            $.ajax({
                type:"post",
                url:"{:url('goods/modifyGoodsCategoryField')}",
                data:{'fieldid':fieldid,'fieldname':fieldname,'fieldvalue':fieldvalue},
                success: function (data) {
                    if(data>0){
                        layer.msg('操作成功', {icon: 1, time: 1000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg('操作失败', {icon: 2, time: 1000});
                    }
                }
            });
        }
    });
    //三级菜单
    function tab_switch(module_id){
        if($(".pid_"+module_id).css('display') != 'none'){
            $(".tab_jian_"+module_id).hide();
            $(".tab_jia_"+module_id).show();
            $(".pid_"+module_id).hide(300);
        }else{
            $(".tab_jian_"+module_id).show();
            $(".tab_jia_"+module_id).hide();
            $(".pid_"+module_id).show(500);
        }
    }
    function delCategory(cate_id) {
        layer.confirm('确认要删除吗？',function(index){
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/deleteGoodsCategory')}",
                data : {
                    'cate_id' : cate_id,
                },
                dataType : "json",
                success : function(data) {
                    if(data['code'] > 0){
                        layer.msg('操作成功', {icon: 1, time: 1000},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data['msg'], {icon: 2, time: 1000});
                    }
                }
            });
        });
    }
</script>
{/block}